package com.whxy02.tolearn.app.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.whxy02.tolearn.app.beans.Exam;
import com.whxy02.tolearn.app.dao.ExamDao;
import com.whxy02.tolearn.app.service.ExamService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ExamServiceImpl implements ExamService {
    private QueryWrapper<Exam> wrapper=new QueryWrapper<>();
    @Resource
    ExamDao examDao;

    @Override
    public List<Exam> getAll() throws Exception {
        return examDao.selectList(null);
    }

    @Override
    public Exam getById(Integer id) throws Exception {
        return examDao.selectById(id);
    }

    @Override
    public int save(Exam exam) throws Exception {
        return examDao.insert(exam);
    }

    @Override
    public int removeById(Integer id) throws Exception {
        return examDao.deleteById(id);
    }

    @Override
    public int change(Exam exam) throws Exception {
        return examDao.updateById(exam);
    }

    @Override
    public Exam getByQuestion(String questionId) throws Exception {
        wrapper.clear();
        wrapper.eq("question_id",questionId);
        return examDao.selectOne(wrapper);
    }
}
